package org.bigdata.framework.admin.web.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * 	给关键词加按钮方法
* @ClassName: CutoutStringUtil  
* @Description: TODO
* @author xuweiheng 
* @date 2017-7-20  
*
 */
public class CutoutStringUtil {
	public static String cutoutStringUtil(String str) {
		Pattern pattern = Pattern.compile(">.*?<"); 
		Matcher matcher = pattern.matcher(str); 
		List<String> listString = new ArrayList<String>();
		StringBuffer sb= new StringBuffer();
		String sh= "";
		String sEnd = "";
		int first = str.indexOf("<");
		int end = str.lastIndexOf(">")+1;
		while(matcher.find()){
			sh = matcher.group().replaceAll("<", "");
			sEnd = sh.replaceAll(">", "");
			listString.add(sEnd);
		}
		if(first >0){
			sb.append("<button type='button' class='btn' style='margin-bottom: 5px; background-color: #FFFAFA; border: 1px solid #FFFAFA;'>"+str.substring(0, first)+"</button>");
		}
		for (int i = 0; i < listString.size(); i++) {
			if(!"".equals(listString.get(i))){
				if(listString.get(i).indexOf("(")>-1){
					sb.append("<button type='button' class='btn' style='margin-bottom: 5px; color:#ffffff; background-color: #FF7256; border: 1px solid #FF7256;'>"+listString.get(i)+"</button> &nbsp;");
				}else{
					sb.append("<button type='button' class='btn' style='margin-bottom: 5px; background-color: #FFFAFA; border: 1px solid #FFFAFA;'>"+listString.get(i)+"</button>");
				}
			}
		}
		if(end<str.length()){
			sb.append("<button type='button' class='btn' style='margin-bottom: 5px; background-color: #FFFAFA; border: 1px solid #FFFAFA;'>"+str.substring(end, str.length())+"</button>");
		}
		return sb.toString();
	}

}
